package com.authsphere.security.account.api.bind.user;

import java.util.Objects;

/**
 * @program: AuthSphere
 * @description:
 * @author: YuKai Fan
 * @create: 2025/3/21 22:30
 **/
public class ExternalUser {
    /**
     * 用户第三方系统的唯一id。在调用方集成该组件时，可以用uuid + source唯一确定一个用户
     *
     * @since 1.3.3
     */
    private String uuid;

    /**
     * 用户名
     */
    private String username;
    /**
     * 用户昵称
     */
    private String nickname;
    /**
     * 用户头像
     */
    private String avatar;
    /**
     * 用户网址
     */
    private String blog;
    /**
     * 所在公司
     */
    private String company;
    /**
     * 位置
     */
    private String location;
    /**
     * 用户邮箱
     */
    private String email;
    /**
     * 用户备注（各平台中的用户个人介绍）
     */
    private String remark;
    /**
     * 性别
     */
    private Integer gender;

    /**
     * 用户来源
     */
    private String source;

    /**
     * 第三方平台返回的原始用户信息
     */
    private String rawUserInfo;

    /**
     * 微信公众号 - 网页授权的登录时可用
     *
     * 微信针对网页授权登录，增加了一个快照页的逻辑，快照页获取到的微信用户的 uid oid 和头像昵称都是虚拟的信息
     */
    private boolean snapshotUser;

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getBlog() {
        return blog;
    }

    public void setBlog(String blog) {
        this.blog = blog;
    }

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Integer getGender() {
        return gender;
    }

    public void setGender(Integer gender) {
        this.gender = gender;
    }

    public String getSource() {
        return source;
    }

    public void setSource(String source) {
        this.source = source;
    }

    public String getRawUserInfo() {
        return rawUserInfo;
    }

    public void setRawUserInfo(String rawUserInfo) {
        this.rawUserInfo = rawUserInfo;
    }

    public boolean isSnapshotUser() {
        return snapshotUser;
    }

    public void setSnapshotUser(boolean snapshotUser) {
        this.snapshotUser = snapshotUser;
    }


    public static final class Builder {
        private String uuid;
        private String username;
        private String nickname;
        private String avatar;
        private String blog;
        private String company;
        private String location;
        private String email;
        private String remark;
        private Integer gender;
        private String source;
        private String rawUserInfo;
        private boolean snapshotUser;

        private Builder() {
        }

        public static Builder anExternalUser() {
            return new Builder();
        }

        public Builder uuid(String uuid) {
            this.uuid = uuid;
            return this;
        }

        public Builder username(String username) {
            this.username = username;
            return this;
        }

        public Builder nickname(String nickname) {
            this.nickname = nickname;
            return this;
        }

        public Builder avatar(String avatar) {
            this.avatar = avatar;
            return this;
        }

        public Builder blog(String blog) {
            this.blog = blog;
            return this;
        }

        public Builder company(String company) {
            this.company = company;
            return this;
        }

        public Builder location(String location) {
            this.location = location;
            return this;
        }

        public Builder email(String email) {
            this.email = email;
            return this;
        }

        public Builder remark(String remark) {
            this.remark = remark;
            return this;
        }

        public Builder gender(Integer gender) {
            this.gender = gender;
            return this;
        }

        public Builder source(String source) {
            this.source = source;
            return this;
        }

        public Builder rawUserInfo(String rawUserInfo) {
            this.rawUserInfo = rawUserInfo;
            return this;
        }

        public Builder snapshotUser(boolean snapshotUser) {
            this.snapshotUser = snapshotUser;
            return this;
        }

        public ExternalUser build() {
            ExternalUser externalUser = new ExternalUser();
            externalUser.setUuid(uuid);
            externalUser.setUsername(username);
            externalUser.setNickname(nickname);
            externalUser.setAvatar(avatar);
            externalUser.setBlog(blog);
            externalUser.setCompany(company);
            externalUser.setLocation(location);
            externalUser.setEmail(email);
            externalUser.setRemark(remark);
            externalUser.setGender(gender);
            externalUser.setSource(source);
            externalUser.setRawUserInfo(rawUserInfo);
            externalUser.setSnapshotUser(snapshotUser);
            return externalUser;
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ExternalUser that = (ExternalUser) o;
        return snapshotUser == that.snapshotUser && Objects.equals(uuid, that.uuid) && Objects.equals(username, that.username) && Objects.equals(nickname, that.nickname) && Objects.equals(avatar, that.avatar) && Objects.equals(blog, that.blog) && Objects.equals(company, that.company) && Objects.equals(location, that.location) && Objects.equals(email, that.email) && Objects.equals(remark, that.remark) && Objects.equals(gender, that.gender) && Objects.equals(source, that.source) && Objects.equals(rawUserInfo, that.rawUserInfo);
    }

    @Override
    public int hashCode() {
        return Objects.hash(uuid, username, nickname, avatar, blog, company, location, email, remark, gender, source, rawUserInfo, snapshotUser);
    }

    @Override
    public String toString() {
        return "ExternalUser{" +
                "uuid='" + uuid + '\'' +
                ", username='" + username + '\'' +
                ", nickname='" + nickname + '\'' +
                ", avatar='" + avatar + '\'' +
                ", blog='" + blog + '\'' +
                ", company='" + company + '\'' +
                ", location='" + location + '\'' +
                ", email='" + email + '\'' +
                ", remark='" + remark + '\'' +
                ", gender=" + gender +
                ", source='" + source + '\'' +
                ", rawUserInfo='" + rawUserInfo + '\'' +
                ", snapshotUser=" + snapshotUser +
                '}';
    }
}
